
//--> Loth 2011 
//--> free simple mail php

package chamans.webphp
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.text.*;
		
		public class Mail extends MovieClip
		{
			private var EMAIL:String;
			private var File_php:String;
			// texte def
		//	private var police:String="FFF Extras";
			private var style:StyleSheet;
			
			private var besoin:Number;
			private var Message:txt;
			private var Mess:txt;
			
			private var sortie:txt;
			private var titre:txt;
			private var nom:txt;
			private var email:txt;
			private var societe:txt;
			private var adresse:txt;
			private var telephone:txt;
			
			private var nom2:txt;
			private var email2:txt;
			private var societe2:txt;
			private var adresse2:txt;
			private var telephone2:txt;
			//private var c03:int=0X303030; 
			//private var C03:Array=[ c03, c03+0X404040, c03-0X202020 ];
			private var c03:int=0X656565; 
			private var C03:Array=[ c03, c03+0X202020, c03-0X202020 ];
			public var content:Sprite;
			
			
			public function Mail(S:StyleSheet):void {
		
				content=new Sprite();
				addChild(content);
				content.x=-175;
				content.y=-200;
				style=S;
				/*style = new StyleSheet();
				style.setStyle("button", {fontSize:'18px', fontFamily:police, leading:'-2px', color:'#DDDDDD', fontWeight : "bold", textAlign :"center"})
				style.setStyle("base2", {fontSize:'12px', fontFamily:police, leading:'0px', color:'#A3CEC4', textAlign :"center"})
				style.setStyle("titre", {fontSize:'14px', fontFamily:police, leading:'-2px', color:'#DDDDDD', fontWeight : "bold"})
				style.setStyle("base", {fontSize:'12px', fontFamily:police, leading:'0px', color:'#A3CEC4', textAlign :"right"})
				style.setStyle("about", {fontSize:'14px', fontFamily:police, leading:'0px', color:'#A3CEC4', textAlign :"right", fontWeight : "bold"})
			*/
				INIT();
			}
			private function INIT():void{
				EMAIL="3dflashlo@gmail.com"; 
				File_php="http://3dflashlo.free.fr/assets/server/email.php";
				var  xml00:XML=<xml><titre>CONTACT</titre></xml>
				titre=new txt({ text:xml00, target:content, style:style, width:300,height:20,  x:25, y:0 })
				var  xml0:XML=<xml><about></about></xml>
				sortie=new txt({ text:xml0, target:content, style:style, width:300,height:20,  x:25, y:20 })
				var  xml:XML=<xml><base></base></xml>
				var  xml1:XML=<xml><base></base></xml>
				nom=new txt({ text:xml, target:content, style:style, width:160,height:20,  x:115, y:48 , S:true, type:1 })
				email=new txt({ text:xml, target:content, style:style, width:160,height:20,  x:115, y:78  , S:true, type:1 })
				societe=new txt({ text:xml, target:content, style:style, width:160,height:20,  x:115, y:121 , S:true, type:1  })
				adresse=new txt({ text:xml, target:content, style:style, width:160,height:20,  x:115, y:151  , S:true, type:1 })
				telephone=new txt({ text:xml, target:content, style:style, width:160,height:20,  x:115, y:181 , S:true, type:1  })
				nom.mouseEnabled=false
				nom2=new txt({ text:xml1, target:content, style:style, width:100,height:20,  x:0, y:48 })
				email2=new txt({ text:xml1, target:content, style:style, width:100,height:20,  x:0, y:78 })
				societe2=new txt({ text:xml1, target:content, style:style, width:100,height:20,  x:0, y:121 })
				adresse2=new txt({ text:xml1, target:content, style:style, width:100,height:20,  x:0, y:151  })
				telephone2=new txt({ text:xml1, target:content, style:style, width:100,height:20,  x:0, y:181 })
				
				nom2.update("NAME");
				email2.update("EMAIL");
				societe2.update("COMPANY");
				adresse2.update("ADRESS");
				telephone2.update("TEL.");
				
				var xmlmes:XML=<xml><base2>MESSAGE</base2></xml>
				Mess=new txt({ text:xmlmes, target:content, style:style, width:250,height:20,  x:50, y:215 });
				Message=new txt({ text:"", target:content, style:style, width:250,height:120,  x:50, y:235, B:false ,W:true ,M:true , S:true, type:1 })
				var B1:Button=new Button(style,  "SEND", content, MailTeste, 104, 370, C03, 70);
				var B2:Button=new Button(style,  "RESET", content, Reset, 176, 370, C03, 70);
			}
			private function Clear(target:MovieClip):void {
				while(target.numChildren) target.removeChildAt(0);
			}
			private function MailTeste(e:Event=null):void{
				var M:String;
				//if (Formulaire.Cmail.text.indexOf("@")!=-1 && Formulaire.Cmail.text.indexOf(".")!=-1 )
				if(nom.TX.text=="")M="/!&#92; EDIT NAME";
				else if(email.TX.text=="")M="/!&#92; EDIT EMAIL";
				else if(Message.TX.text=="")M="/!&#92; EDIT MESSAGE";
				else if(nom.TX.text!="" && email.TX.text!="" && Message.TX.text!=""){   SendFormulaire()   }
				sortie.update(M);
			}
			public function Reset(e:Event=null):void
			{  
				Message.TX.text="";
				nom.update("");  email.update(""); 
				societe.update("");   adresse.update("");  telephone.update("");
				sortie.update("");
				besoin=0;
			}
			/////////////////////////
			//////////////////////////
			
			private function SendFormulaire(e:Event=null):void{
				var urlLoader:URLLoader = new URLLoader(); 
				var urlRequest:URLRequest = new URLRequest(File_php);
				var urlVariables:URLVariables = new URLVariables();
				
				urlVariables.MAIL = EMAIL
				urlVariables.mess = Message.TX.text;
				
				urlVariables.nom = nom.TX.text; 
				urlVariables.email = email.TX.text; 
				urlVariables.societe = societe.TX.text;
				urlVariables.ville = adresse.TX.text;
				urlVariables.telephone = telephone.TX.text; 
				
				urlVariables.besoin = besoin;
				
				sortie.update("Send in progress")
				urlRequest.data = urlVariables; 
				urlRequest.method = URLRequestMethod.POST; 
				urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
				urlLoader.load(urlRequest); 
				urlLoader.addEventListener(ProgressEvent.PROGRESS, CHarge); 
				urlLoader.addEventListener(Event.COMPLETE, donneesChargees); 
				urlLoader.addEventListener(IOErrorEvent.IO_ERROR, erreur); 
			}
			private function CHarge(e:ProgressEvent):void 
			{ 
				var loader:URLLoader = URLLoader(e.target);
				var vars:URLVariables=new URLVariables(loader.data);
				sortie.update("Send in progress")
			} 
			private function donneesChargees(e:Event):void 
			{ 
				var loader:URLLoader = URLLoader(e.target);
				var vars:URLVariables=new URLVariables(loader.data);
				
				sortie.update(vars.answer)
				if(vars.answer!='Error Email')Reset();
			} 
			private function erreur(e:IOErrorEvent):void 
			{ 
				var loader:URLLoader = URLLoader(e.target);
				var vars:URLVariables=new URLVariables(loader.data);
				sortie.update(vars.answer)
			}
		
		}}